package graph;

public class GraphTest {
    public static void main(String[] args) {
        dijkstraTest();
        floydTest();
    }

    public static void test(){
        Graph graph = new Graph(5);
        graph.addVertex("A");
        graph.addVertex("B");
        graph.addVertex("C");
        graph.addVertex("D");
        graph.addVertex("E");
        graph.addEdge("B","C",1);
        graph.addEdge("B","A",1);
        graph.addEdge("B","D",1);
        graph.addEdge("B","E",1);
        graph.addEdge("A","C",1);
        graph.addEdge("A","E",1);
        graph.printGraphData();
        System.out.println("dfs======================");
        graph.dfs("A");
        System.out.println("bfs======================");
        graph.bfs("A");
    }

    public static void primTest(){
        Graph graph = new Graph(7);
        initGraph(graph);
        graph.primSmallestTree("A");
    }
    public static void kruskalTest(){
        Graph graph = new Graph(7);
        initGraph(graph);
        graph.kruskalSmallestTree();
    }
    public static void dijkstraTest(){
        /*正确结果：
            C->A 7
            C->B 12
            C->C 0
            C->D 17
            C->E 8
            C->F 13
            C->G 9
            前驱结点  2 0 2 5 2 4 0
        * */
        Graph graph = new Graph(7);
        initGraph(graph);
        graph.dijkstra("C");
    }
    public static void initGraph(Graph graph){
        graph.addVertex("A");
        graph.addVertex("B");
        graph.addVertex("C");
        graph.addVertex("D");
        graph.addVertex("E");
        graph.addVertex("F");
        graph.addVertex("G");
        graph.addEdge("A","B",5);
        graph.addEdge("A","G",2);
        graph.addEdge("A","C",7);
        graph.addEdge("B","G",3);
        graph.addEdge("B","D",9);
        graph.addEdge("C","E",8);
        graph.addEdge("D","F",4);
        graph.addEdge("E","G",4);
        graph.addEdge("E","F",5);
        graph.addEdge("F","G",6);
    }
    public static void floydTest(){
        Graph graph = new Graph(7);
        initGraph(graph);
        graph.floyd("C");
    }
}
